package com.yq.leetcodeOld.stack;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @ClassName MyStack225
 * @Description 放到栈2中，复制到栈1中
 * @Author yaoqiang
 * @Date 2022/3/25 12:28
 * @Version 1.0
 */
public class MyStack225 {
    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);stack.push(2);
        int b = stack.pop();
        int c = stack.top();
        boolean d = stack.empty();
        System.out.println( b + " " + c + " " + d);
    }}

class MyStack {
    private Queue<Integer> q1, q2;
    MyStack() {q1 = new LinkedList<>();q2 = new LinkedList<>();}
    public void push(int x){
        q2.offer(x);
        while (!q1.isEmpty()){
            q2.offer(q1.poll());
        }
        Queue<Integer> temp=q2;
        q2=q1;
        q1=temp;
    }
    public  int pop(){return q1.poll();}
    public int top(){return q1.peek();}
    public boolean empty(){return q1.isEmpty();}
}
